//
// Created by chizuru on 2025/9/2.
//

#pragma once
#include <functional>
#include <thread>
#include <atomic>
#include <chrono>
#include <mutex>


class ConnectivityMonitor {
public:
    ConnectivityMonitor(std::function<bool()> checkFunc, std::function<void(bool)> observer, std::chrono::milliseconds interval = std::chrono::milliseconds(1000));

    ~ConnectivityMonitor() ;

    void start() ;
    void stop() ;

private:
    std::function<bool()> checkFunc;
    std::function<void(bool)> observer;
    std::atomic_bool running{false};
    std::thread worker;
    std::chrono::milliseconds interval;
    std::mutex mtx;
    std::condition_variable cv;
};

